package at.sysarch.filter;

import javax.media.jai.JAI;
import javax.media.jai.PlanarImage;

import at.pimpmypipe.filter.DataEnrichmentFilter;
import at.sysarch.domain.TransferImage;
import at.sysarch.utils.DateHelper;

public class StoreFilter extends DataEnrichmentFilter<TransferImage, TransferImage>{

	@Override
	protected boolean fillEntity(TransferImage nextVal, TransferImage entity) {
		PlanarImage oldImage;
		oldImage = nextVal.getModifiedImage();	
		String fileName = new StringBuilder().append("result").append(DateHelper.format()).append(".jpg").toString();
		JAI.create("filestore", oldImage, fileName, "JPEG");
		
		entity.setModifiedImage(oldImage);
		entity.setSourceImage(nextVal.getSourceImage());
		
		return true;
	}

	@Override
	protected TransferImage getNewEntityObject() {
		return new TransferImage();
	}

}
